import taichi as ti 

ti.init(arch = ti.cuda)

n = 512
res_x = n
res_y = n

pixels = ti.Vector.field(3, ti.f32,shape = (res_x, res_y))


@ti.func
def smoothstep(e1,e2,v):
    t = (v-e1)/float(e2-e1)
    if t <=0.0:
        t = 0.0
    if t >=1.0:
        t = 1.0 
    return (3-2*t)*t**2

@ti.func
def circle(pos,center,readius,blur):
    r = (pos-center).norm()
    t = 0.0
    
    if blur > 0.0:
        t = smoothstep(1.0,1.0-blur,r/readius)
    return t
  
@ti.kernel
def render ():
    for i,j in pixels :
        color = ti.Vector([0.0,0.0,0.0])
        pixels[i,j] = color

        pos = ti.Vector([i,j])
        center = ti.Vector([res_x*0.5,res_y*0.5])

        radius = 100
        c = circle(pos,center,radius,0.4)
 
        color = ti.Vector([40.0,1.0,0.0])
        pixels[i,j] =color


gui =ti.GUI("CANVAS",res=(res_x,res_y))

for i in range(1000000):
    render()
    gui.set_image(pixels)
    gui.show()


